/*
 * @Author: yangchunpeng ruochengflag@163.com
 * @Date: 2025-02-26 20:22:43
 * @LastEditors: yangchunpeng ruochengflag@163.com
 * @LastEditTime: 2025-02-27 17:54:04
 * @FilePath: /pure-admin-thin-main/src/utils/shaders/shadersUtils.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 导入着色器代码
import naturalShader from "./natural.frag?raw"; //创建自然效果滤镜
import defoggingShader from "./defogging.frag?raw"; // 创建去雾效果滤镜
import sharpenShader from "./sharpen.frag?raw"; //创建锐化效果滤镜
import grayscaleShader from "./grayscale.frag?raw"; // 创建黑白效果滤镜
import invertShader from "./invert.frag?raw"; // 创建反色效果滤镜
import vintageShader from "./vintage.frag?raw"; // 创建老照片效果滤镜
// import gaussianBlurShader from "./gaussianblur.frag?raw"; // 创建高斯模糊滤镜
import colorSplitShader from "./color-split.frag?raw"; //色调分离
import mosaicShader from "./mosaic.frag?raw"; // 创建马赛克效果滤镜
import * as PIXI from "pixi.js";
import { TiltShiftFilter } from "pixi-filters";
// 创建自然效果滤镜
export const createNaturalFilter = () => {
  return new PIXI.Filter(null, naturalShader, {
    brightness: 1.05, // 轻微提高亮度
    saturation: 1.1, // 适度增加饱和度
    contrast: 1.1, // 轻微提升对比度
    temperature: 0.15, // 添加暖色调
    gamma: 1.1 // gamma校正
  });
};

// 创建去雾效果滤镜
export const createDefoggingFilter = () => {
  return new PIXI.Filter(null, defoggingShader, {
    fogAmount: 0.8 // 去雾强度
  });
};

// 创建锐化效果滤镜
export const createSharpenFilter = () => {
  return new PIXI.Filter(null, sharpenShader, {
    dimensions: [800, 600], // 图像尺寸
    strength: 0.5 // 锐化强度
  });
};
// 创建黑白效果滤镜
export const createGrayscaleFilter = () => {
  return new PIXI.Filter(null, grayscaleShader);
};

// 创建反色效果滤镜
export const createInvertFilter = () => {
  return new PIXI.Filter(null, invertShader);
};

// 创建老照片效果滤镜
export const createVintageFilter = () => {
  return new PIXI.Filter(null, vintageShader, {
    sepia: 0.8, // 80%的复古程度
    noise: 0.2, // 20%的噪点
    scratch: 0.1 // 10%的划痕
  });
};
// 定义 options 的类型
interface Options {
  blur?: number;
  gradientBlur?: number;
  offset?: number;
  gradientOffset?: number;
}
/**
 * 创建高斯模糊滤镜
 * @param {PIXI.Sprite} sprite - 需要应用模糊效果的精灵对象
 * @param {Object} options - 模糊效果的配置选项
 * @returns {TiltShiftFilter} 返回倾斜位移滤镜实例
 */
export const createGaussianBlurFilter = sprite => {
  const startPoint = new PIXI.Point(0, 0);
  const endPoint = new PIXI.Point(sprite.width, sprite.height);
  return new TiltShiftFilter(50, 0, startPoint, endPoint);
};

// 创建色调分离滤镜
export const createColorSplitFilter = () => {
  return new PIXI.Filter(null, colorSplitShader, {
    offset: [5.0, 0.0], // 水平偏移5个像素
    angle: 0.0 // 初始角度为0度
  });
};

// 创建马赛克效果滤镜
export const createMosaicFilter = ({ width, height }) => {
  console.log("createMosaicFilter", width, height);

  return new PIXI.Filter(null, mosaicShader, {
    uResolution: { x: width, y: height }, // 应该是你的画布分辨率
    uTileSize: { x: 20, y: 20 } // 马赛克块的大小
  });
};
